package mobile.pubcrawler;

import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.widget.ListView;

public class PubListView extends ListView {

	private Context context;
	private int notAvailableSpaceVertical = 70;
	
	public PubListView(Context context) {
		super(context);
		this.context = context;
	}
	
	public PubListView(Context context, AttributeSet set) {
		super(context, set);
		this.context = context;
	}
	
	public PubListView(Context context, AttributeSet set, int defaultStyle) {
		super(context, set, defaultStyle);
		this.context = context;
	}
	
	@Override
	protected void onMeasure(int wMeasureSpec, int hMeasureSpec) {
		int measuredHeight = measureHeight(hMeasureSpec);
		int measuredWidth = measurewidth(wMeasureSpec);
		setMeasuredDimension(measuredWidth, measuredHeight);
	}
	
	private int measureHeight(int measureSpec) {
		DisplayMetrics displaymetrics = new DisplayMetrics();
		((Activity)context).getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);  
		return displaymetrics.heightPixels-notAvailableSpaceVertical;
	}
	
	private int measurewidth(int measureSpec) {
		return MeasureSpec.getSize(measureSpec);
	}
	
	public void setNotAvailableSpaceVertical(int pixel) {
		notAvailableSpaceVertical = pixel;
	}
	
	public int getNotAvailableSpaceVertical() {
		return notAvailableSpaceVertical;
	}
	
}
